﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

using View;

using DevExpress.XtraNavBar;
using DevExpress.XtraGrid.Views.Layout;
using DevExpress.XtraGrid.Columns;
using TestMySqlConnetPoll;
using DevExpress.XtraTreeList.Nodes;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraSplashScreen;
using DevExpress.XtraGrid.Views.Base;
using System.Threading;

namespace View.LK
{
    public partial class LK : DevExpress.XtraEditors.XtraForm
    {
        private string SelectMenu = "";
        private string LinkMenu = "";
        private GridView view;
        
        public LK()
        {
            InitializeComponent();
            view = this.gridView1 as GridView;
            view.IndicatorWidth = 40;
            SelectMenu = "硬件平台";
            BindDataTable(c_RealTimeValue.HostHardwarePlatform);
        }
        public void BindDataTable(DataTable Tb)
        {           
         
            view.Columns.Clear();
            
            this.Text = Tb.TableName + "   实时值";
            if (Tb == null)
            {
                gridControl1.DataSource = c_RealTimeValue.HostHardwarePlatform;
            }
            else
            {
                gridControl1.DataSource = Tb;                
            }
            view.BestFitColumns();
            
        }

        private void gridView1_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
            if (e.Info.IsRowIndicator)
            {
                if (e.RowHandle >= 0)
                {
                    e.Info.DisplayText = (e.RowHandle+1).ToString();
                }
            }
        }

        int kk = 0;
        private void navBarControl4_GroupExpanded(object sender, NavBarGroupEventArgs e)
        {
            string s = e.Group.Caption;
            if (s == SelectMenu) return;
            
            SelectMenu = s;
            
            if (s == "硬件平台") BindDataTable(c_RealTimeValue.HostHardwarePlatform);
            else if (s == "联锁接口进路信息") BindDataTable(c_RealTimeValue.LianSuoJieKouRouteInfo);
            else if (s == "联锁改方命令信息") BindDataTable(c_RealTimeValue.LianSuoGaiFangCommandInfo);
            else if (s == "联锁改方命令回执信息") BindDataTable(c_RealTimeValue.LianSuoGaiFangCommandRet);
            else if (s == "站间改方命令信息") BindDataTable(c_RealTimeValue.ZhanJianGaiFangCommandInfo);
            else if (s == "站间改方回执信息") BindDataTable(c_RealTimeValue.ZhanJianGaiFangCommandRet);
            else if (s == "站间边界信息") BindDataTable(c_RealTimeValue.ZhanJianBoundaryInfo);
            else if (s == "区间方向口信息") BindDataTable(c_RealTimeValue.SendToLianSuoInfo);
            else if (s == "临时限速状态") BindDataTable(c_RealTimeValue.TemporaryLimitSpeedState);
            else if (s == "区段编码信息") BindDataTable(c_RealTimeValue.SectionEncodeInfo);
            else if (s == "应答器报文编码信息") BindDataTable(c_RealTimeValue.TransponderEncodeInfo);
            else if (s == "状态信息")
            {
                BindDataTable(c_RealTimeValue.Statue_Info.Tables["PIO采集继电器"]);
                LinkMenu = "PIO采集继电器";
            }            
        }

        private void navBarControl4_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
            string s = e.Link.Caption;
            if (s == LinkMenu) return;
            LinkMenu = s;
            if (e.Link.Group.Caption == "状态信息")
            {
                for (int i = 0; i < c_RealTimeValue.Statue_Info.Tables.Count; i++)
                {
                    if (s == c_RealTimeValue.Statue_Info.Tables[i].TableName)
                    {
                        BindDataTable(c_RealTimeValue.Statue_Info.Tables[i]);
                    }
                }
            }
        }        
    }
}